'use strict'
let nunjucks = require("nunjucks")

function creatConf(path, opts) {
    path = path || 'html';
    opts = opts || {};
    let conf = {
        autoescape: opts.autoescape || true,
        throwOnUndefined: opts.throwOnUndefined || false,
        trimBlocks: opts.trimBlocks || false,
        lstripBlocks: opts.lstripBlocks || false,
        watch: opts.watch || true,
        noCache: opts.noCache || true
    }
    let evn = nunjucks.configure('html', conf);
    return evn;
}

module.exports = async(etc, next) => {
    let evn = creatConf();
    etc.render = function(path, opts) {
        etc.body = evn.render(path, opts);
    }
    await next();
}